home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr49 / 274_01.zip / ARRAY.ART < prev    next >
Text File  |  1993-04-01  |  9KB  |  316 lines

  1.                                  Arrays for C
  2.                             Article on Arrays for C
  3.                                  Version 1.00
  4.  
  5.  
  6.  
  7.         INTRO
  8.  
  9.         Arrays  for  C version 1.00 is a set of C   header   files   that 
  10.         simplifies  array  handling  in C. They  allow  four  classes  of 
  11.         operations:  unary  (on  a single  array),  binary  (on  multiple 
  12.         arrays),  fill  arrays, and information on arrays. They  work  on 
  13.         mixed  types  (including constants), and should work  on  a  wide 
  14.         range  of  compilers  and  computers  without  modification.  The 
  15.         routines are available as shareware or retail.
  16.  
  17.  
  18.         OVERVIEW
  19.  
  20.             The  routines  were  written to help me handle  arrays  in  a 
  21.         uniform  manner, and to have a set of canned routines  that  were 
  22.         debugged, and capable of doing operations on all kinds of arrays. 
  23.  
  24.         The routines are broken up into the following types:
  25.  
  26.         Binary Operations       Add, Multiply, etc. 2 arrays/constant
  27.         Unary Operations        Negate, Assign, Absolute, etc. an array
  28.         Fill Operations         Fill array with index, values etc. 
  29.         Info about Array        Min, Max, etc. of an array
  30.  
  31.         There are also routines to call a function in each category. 
  32.  
  33.             The  routines  work by substituting your call  into  a  while 
  34.         loop.  This was the ONLY way I could find to use different  types 
  35.         of  arrays/constants  in an expression that would  be  compatible 
  36.         across  a  wide  range of compilers/systems. (I  spent  3  months 
  37.         trying all kinds of different ways, but none would work on ALL of 
  38.         the  compilers  I  could  test with,  except  this  method).  The 
  39.         routines  have  been  tested with  multiple  compilers  including 
  40.         Microsoft 5.0, Turbo 1.5 and Aztec 3.40B on PC & AT Clones.
  41.  
  42.         USAGE
  43.  
  44.             In order to use the routines, you include the file ARRAY.H in 
  45.         your program. i.e.:
  46.  
  47.             #include <stdio.h>
  48.             #include "array.h"
  49.  
  50.             main() 
  51.             { 
  52.                 .
  53.                 .
  54.                 .
  55.  
  56.         Then use the routines whenever/wherever you need them.
  57.  
  58.  
  59.  
  60.  
  61.                             James P. Cruse, Sci-Pic
  62.                 919 Capitola Ave, Suite 41, Capitola, CA 95010
  63.                                 (408) 475-7444
  64.                                  Arrays for C
  65.                             Article on Arrays for C
  66.                                  Version 1.00
  67.  
  68.  
  69.  
  70.         USAGE (continued)
  71.  
  72.         The Functions all have a uniform naming format:
  73.  
  74.                 X_NAME, where X is:
  75.                         a   for single array operations
  76.                         aa for multiple array operations
  77.                         ac for array & constant, 
  78.                     and ca for constant & array
  79.                         And NAME is the operation to be done. 
  80.  
  81.                 For Example:
  82.  
  83.                         aa_add()        add two arrays
  84.                         ac_add()        add array & constant
  85.                         a_neg()         negate array
  86.                         a_index()       fill array with index
  87.  
  88.  
  89.  
  90.         TEST/EXAMPLES 
  91.  
  92.             There are example routines included. There is both an integer 
  93.         and  a  float example: A_testf.c does a floating  point  example, 
  94.         proving  numerically sin^2+cos^2=1; and a_testi does  an  integer 
  95.         example,  showing the sum of an arithmetic sequence is  a  simple 
  96.         calculation.
  97.  
  98.  
  99.  
  100.         CUSTOMIZATION OPTIONS
  101.  
  102.             There  are a few #defines used to select  compiler  dependent 
  103.         options:   does  the  compiler  allow  curly  braces  without   a 
  104.         proceeding  if  or while, and for taking the Min and Max  of  two 
  105.         elements.
  106.  
  107.             There  are also #defines selecting which routines to link  in 
  108.         by  default  (which you can override at include time),  and  what 
  109.         variable name and type to use for the loop variable.
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.                             James P. Cruse, Sci-Pic
  125.                 919 Capitola Ave, Suite 41, Capitola, CA 95010
  126.                                 (408) 475-7444
  127.                                  Arrays for C
  128.                             Article on Arrays for C
  129.                                  Version 1.00
  130.  
  131.  
  132.         QUICK SUMMARY
  133.  
  134.         The following is a quick description of the operations available. 
  135.         Remember  to prepend the a_,aa_,ac_,ca_ to the name depending  on 
  136.         the  parameters  to the operation. Each list is  followed  by  an 
  137.         example  of a couple of the functions. 
  138.  
  139.         Binary Operations: (a_binop.h)
  140.             add, sub, mul, div, min, max, mod (%,modulo),
  141.             equ (==), geq (>=), leq (<=), gtr (>), les (<),
  142.             fun (function), t_fun (typed function)
  143.  
  144.             aa_add(n,d,a,b)             d[] = a[] + b[]
  145.             ac_min(n,d,a,c)             d[] = ARR_MIN(a[],c)
  146.             ca_sub(n,d,c,a)             d[] = c - a[]
  147.  
  148.             aa_fun(n,d,a,b,f)           d[] = f(a[],b[])
  149.             ac_t_fun(n,d,a,c,f,t)       d[] = f( (t) a[] , (t) c )
  150.  
  151.  
  152.         Unary Operations: (a_unop.h)
  153.             cpy (copy,assign), neg (negate), abs (absolute value), 
  154.             rsum (running sum), rprod (running product),
  155.             rmin (running min), rmax (running max),
  156.             fun (function), t_fun (typed function)
  157.             scale (scale&offset)
  158.  
  159.             a_cpy(n,d,a)                d[] = a[] 
  160.             a_rsum                      d[i] = d[i-1] + a[i]
  161.             a_rmax                      d[i] = ARR_MAX( d[i-1] , a[i] )
  162.  
  163.             a_scale(n,d,a,s,o)          d[] = o + s*a[]
  164.  
  165.             a_fun(n,d,a,f)              d[] = f(a[])
  166.             a_t_fun(n,d,a,f,t)          d[] = (t) f( (t) a[] )
  167.  
  168.  
  169.         Info Operations: (a_info.h)
  170.             sum, prod, min, max, minmax
  171.  
  172.             a_sum(n,d,a)                d = a[0] + a[1] + ... + a[n-1]
  173.             a_min(n,d,a)                d = min( a[0] , ... , a[n-1] )
  174.             a_minmax(n,l,u,a)           l = min( a[0] , ... , a[n-1] ),
  175.                                    and  u = max( a[0] , ... , a[n-1] )
  176.  
  177.  
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.                             James P. Cruse, Sci-Pic
  188.                 919 Capitola Ave, Suite 41, Capitola, CA 95010
  189.                                 (408) 475-7444
  190.                                  Arrays for C
  191.                             Article on Arrays for C
  192.                                  Version 1.00
  193.  
  194.  
  195.         QUICK SUMMARY (continued)
  196.  
  197.         Fill Operations: (a_fill.h)
  198.  
  199.             index, indoff (index+offset), fill (exclusive), 
  200.             ifill (inclusive), t_fill (typed exclusive fill), 
  201.             t_ifill (typed inclusive fill) 
  202.             scale (scale&offset), 
  203.             assign, f_fun (function), i_fun, (function w/index param),
  204.             t_i_fun (typed function w/index param)
  205.  
  206.             a_indoff(n,d,c)             d[i] = i + c
  207.             a_assign(n,d,c)             d[] = c
  208.             a_i_scale(n,d,s,o)          d[i] = s*i + o
  209.  
  210.  
  211.             a_fill(n,d,s,e)             d[0] = s, d[i] = s+(e-s)/n, 
  212.                                             d[n] (would be) e 
  213.  
  214.             a_t_ifill(n,d,s,e)          d[0] = s, 
  215.                                         d[i] = s+((t)(e-s))/(n-1), 
  216.                                         d[n-1] = e
  217.  
  218.             a_f_fun(n,d,f)              d[] = f()
  219.             a_t_i_fun(n,d,f,t)          d[i] = f( (t) i )
  220.  
  221.  
  222.  
  223.  
  224.  
  225.  
  226.  
  227.  
  228.  
  229.  
  230.  
  231.  
  232.  
  233.  
  234.  
  235.  
  236.  
  237.  
  238.  
  239.  
  240.  
  241.  
  242.  
  243.  
  244.  
  245.  
  246.  
  247.  
  248.  
  249.  
  250.                             James P. Cruse, Sci-Pic
  251.                 919 Capitola Ave, Suite 41, Capitola, CA 95010
  252.                                 (408) 475-7444
  253.                                  Arrays for C
  254.                             Article on Arrays for C
  255.                                  Version 1.00
  256.  
  257.  
  258.             I  hope you will try the routines, and find them of  use.  If 
  259.         there  are any questions, or there are other routines  you  would 
  260.         like to see implemented, please feel free to call or write. 
  261.  
  262.  
  263.                                    Sincerely,
  264.  
  265.  
  266.                                  James P. Cruse
  267.                                      Sci-Pic
  268.                                 919 Capitola Ave
  269.                                     Suite 41
  270.                                Capitola, CA 95010
  271.                                  (408) 475-7444
  272.  
  273.  
  274.  
  275.  
  276.  
  277.  
  278.  
  279.  
  280.  
  281.  
  282.  
  283.  
  284.  
  285.  
  286.  
  287.  
  288.  
  289.  
  290.  
  291.  
  292.  
  293.  
  294.  
  295.  
  296.  
  297.  
  298.  
  299.  
  300.  
  301.  
  302.  
  303.  
  304.  
  305.  
  306.  
  307.  
  308.  
  309.  
  310.  
  311.  
  312.  
  313.                             James P. Cruse, Sci-Pic
  314.                 919 Capitola Ave, Suite 41, Capitola, CA 95010
  315.                                 (408) 475-7444
  316.